package com.lk.demo.controller;

import com.lk.demo.service.HelloService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/hello")
public class HelloController {

    HelloService helloService;
    private static final Logger log = LoggerFactory.getLogger(HelloController.class);

    @Autowired
    public HelloController(HelloService helloService){
        this.helloService = helloService;
    }
    @GetMapping
    public String hello(){
        return "Hello World!";
    }

    @GetMapping("/custom")
    public Map<String, Object> helloMyConfig(){
        Map<String, Object> res = new HashMap<>();
        res.put("Got conf by @Value", helloService.getMyConfigByValueAnnotation());
        res.put("Got conf by Configuration Class", helloService.getMyConfigByConfigClass());
        return res;
    }

    @GetMapping("/log")
    public String log(){
        log.trace("*****trace*****");
        log.debug("*****debug*****");
        log.info("*****info*****");
        log.warn("*****warn*****");
        log.error("*****error*****");
        return "*****see log info in your log file****";
    }
}
